<!doctype html>
<html>
<head>
  <title>多姿蜜</title>
  <meta name="Keywords" content="多姿蜜">
  <meta name="Description" content="多姿蜜">
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
  {css href="__STATIC__/admin/css/reset.css" /}
  {css href="__STATIC__/admin/css/style.css" /}
  {css href="__STATIC__/common/layer/skin/default/layer.css" /}
</head>
<body class="loginBg">
<div class="wrapper">
  <div class="login">
    <p class="center mb15">
      <input type="text" name="name" class="loginName" placeholder="请输入用户名">
    </p>
    <p class="center mb15 po">
      <input type="password" name="passwprd" class="loginPass" placeholder="请输入密码">
    </p>
    <p class="code clr">
      <input type="text" name="code" placeholder="请输入验证码">
      <img id="captcha_img" src="{:url('admin/login/verify_c',array())}" title="点击刷新"/>
    </p>
    <p class="center">
      <a href="javascript:;"><span class="loginBtn">登录</span></a>
    </p>
  </div>

</div>
{js href="__STATIC__/admin/js/jquery.min.js" /}
{js href="__STATIC__/common/layer/layer.js" /}
<script type="text/javascript">
    $('.loginBtn').on('click',function(){
        var name = $('input[name="name"]').val(),
            pass = $('input[name="passwprd"]').val(),
            code = $('input[name="code"]').val();
        if ($.trim(name)=='') {
            layer.alert('请输入用户名');
            return false;
        }
        if ($.trim(pass)=='') {
            layer.alert('请输入密码');
            return false;
        }
        if ($.trim(code)=='') {
            layer.alert('请输入验证码');
            return false;
        }
        $.post("{:url('admin/login/login')}", {
            username : name,
            password : pass,
            verify : code,
            //remember_status : remember_status
        }, function(data){
            if(data.code==1){
                location.href = "{:url('admin/index/index')}";
            }else if(data.code==3){
                layer.alert(data.msg);
                if( verifyimg.indexOf('?')>0){
                    captcha_img.attr("src", verifyimg+'&random='+Math.random());
                }else{
                    captcha_img.attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
                }
                return false;
            }else if(data.code==4){
                layer.alert(data.msg);
                return false;
            }else{
                layer.alert(data.msg);
                if( verifyimg.indexOf('?')>0){
                    captcha_img.attr("src", verifyimg+'&random='+Math.random());
                }else{
                    captcha_img.attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
                }
            }
        }, 'json');
    });

    $(document).keyup(function(event){
        if(event.keyCode ==13){
            $(".loginBtn").trigger("click");
        }
    });

    // 验证码生成
    var captcha_img = $('#captcha_img');
    var verifyimg = captcha_img.attr("src");
    captcha_img.attr('title', '点击刷新');
    captcha_img.click(function(){
        if( verifyimg.indexOf('?')>0){
            $(this).attr("src", verifyimg+'&random='+Math.random());
        }else{
            $(this).attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
        }
    });

</script>
</body>
</html>